## covariate balance tests
## (these are done on the samples used for the analysis of attitudes 
## toward immigration, because these encompass more respondents than 
## the ones for attitudes toward immigrants)


#smol2
summary(RDestimate(agea ~ lamp, data = smol2, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ lamp, data = smol2, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ lamp, data = smol2, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ lamp, data = smol2, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ lamp, data = smol2, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ lamp, data = smol2, cutpoint = 0, bw = 30))

#smol4
summary(RDestimate(agea ~ one | cntry, data = smol4, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ one | cntry, data = smol4, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ one | cntry, data = smol4, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ one | cntry, data = smol4, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ one | cntry, data = smol4, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ one | cntry, data = smol4, cutpoint = 0, bw = 30))

#smol6
summary(RDestimate(agea ~ two | cntry, data = smol6, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ two | cntry, data = smol6, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ two | cntry, data = smol6, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ two | cntry, data = smol6, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ two | cntry, data = smol6, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ two | cntry, data = smol6, cutpoint = 0, bw = 30))

#smol8
summary(RDestimate(agea ~ three | cntry, data = smol8, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ three | cntry, data = smol8, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ three | cntry, data = smol8, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ three | cntry, data = smol8, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ three | cntry, data = smol8, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ three | cntry, data = smol8, cutpoint = 0, bw = 30))

#smol10
summary(RDestimate(agea ~ four | cntry, data = smol10, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ four | cntry, data = smol10, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ four | cntry, data = smol10, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ four | cntry, data = smol10, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ four | cntry, data = smol10, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ four | cntry, data = smol10, cutpoint = 0, bw = 30))

#smol12
summary(RDestimate(agea ~ five | cntry, data = smol12, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ five | cntry, data = smol12, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ five | cntry, data = smol12, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ five | cntry, data = smol12, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ five | cntry, data = smol12, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ five | cntry, data = smol12, cutpoint = 0, bw = 30))

#smol14
summary(RDestimate(agea ~ six | cntry, data = smol14, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ six | cntry, data = smol14, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ six | cntry, data = smol14, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ six | cntry, data = smol14, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ six | cntry, data = smol14, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ six | cntry, data = smol14, cutpoint = 0, bw = 30))

#smol16
summary(RDestimate(agea ~ seven | cntry, data = smol16, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ seven | cntry, data = smol16, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ seven | cntry, data = smol16, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ seven | cntry, data = smol16, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ seven | cntry, data = smol16, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ seven | cntry, data = smol16, cutpoint = 0, bw = 30))

#smol18
summary(RDestimate(agea ~ eight | cntry, data = smol18, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ eight | cntry, data = smol18, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ eight | cntry, data = smol18, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ eight | cntry, data = smol18, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ eight | cntry, data = smol18, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ eight | cntry, data = smol18, cutpoint = 0, bw = 30))

#smol20
summary(RDestimate(agea ~ nine | cntry, data = smol20, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ nine | cntry, data = smol20, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ nine | cntry, data = smol20, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ nine | cntry, data = smol20, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ nine | cntry, data = smol20, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ nine | cntry, data = smol20, cutpoint = 0, bw = 30))

#smol22
summary(RDestimate(agea ~ ten | cntry, data = smol22, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ ten | cntry, data = smol22, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ ten | cntry, data = smol22, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ ten | cntry, data = smol22, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ ten | cntry, data = smol22, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ ten | cntry, data = smol22, cutpoint = 0, bw = 30))

#smol24
summary(RDestimate(agea ~ eleven | cntry, data = smol24, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ eleven | cntry, data = smol24, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ eleven | cntry, data = smol24, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ eleven | cntry, data = smol24, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ eleven | cntry, data = smol24, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ eleven | cntry, data = smol24, cutpoint = 0, bw = 30))

#smol26
summary(RDestimate(agea ~ twelve | cntry, data = smol26, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ twelve | cntry, data = smol26, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ twelve | cntry, data = smol26, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ twelve | cntry, data = smol26, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ twelve | cntry, data = smol26, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ twelve | cntry, data = smol26, cutpoint = 0, bw = 30))

#smol28
summary(RDestimate(agea ~ thirteen | cntry, data = smol28, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ thirteen | cntry, data = smol28, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ thirteen | cntry, data = smol28, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ thirteen | cntry, data = smol28, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ thirteen | cntry, data = smol28, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ thirteen | cntry, data = smol28, cutpoint = 0, bw = 30))


#smol30
summary(RDestimate(agea ~ thirteen, data = smol30, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ thirteen, data = smol30, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ thirteen, data = smol30, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ thirteen, data = smol30, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ thirteen, data = smol30, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ thirteen, data = smol30, cutpoint = 0, bw = 30))

#smol32
summary(RDestimate(agea ~ fourteen | cntry, data = smol32, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ fourteen | cntry, data = smol32, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ fourteen | cntry, data = smol32, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ fourteen | cntry, data = smol32, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ fourteen | cntry, data = smol32, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ fourteen | cntry, data = smol32, cutpoint = 0, bw = 30))

#smol34
summary(RDestimate(agea ~ fifteen | cntry, data = smol34, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ fifteen | cntry, data = smol34, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ fifteen | cntry, data = smol34, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ fifteen | cntry, data = smol34, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ fifteen | cntry, data = smol34, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ fifteen | cntry, data = smol34, cutpoint = 0, bw = 30))

#smol36
summary(RDestimate(agea ~ fifteen, data = smol36, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ fifteen, data = smol36, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ fifteen, data = smol36, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ fifteen, data = smol36, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ fifteen, data = smol36, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ fifteen, data = smol36, cutpoint = 0, bw = 30))

#smol39
summary(RDestimate(agea ~ run | cntry, data = smol39, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ run | cntry, data = smol39, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ run | cntry, data = smol39, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ run | cntry, data = smol39, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ run | cntry, data = smol39, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ run | cntry, data = smol39, cutpoint = 0, bw = 30))

#smol40
summary(RDestimate(agea ~ run, data = smol40, cutpoint = 0, bw = 30))
summary(RDestimate(gndr ~ run, data = smol40, cutpoint = 0, bw = 30))
summary(RDestimate(wkhtot ~ run, data = smol40, cutpoint = 0, bw = 30))
summary(RDestimate(freehms ~ run, data = smol40, cutpoint = 0, bw = 30))
summary(RDestimate(stfhlth ~ run, data = smol40, cutpoint = 0, bw = 30))
summary(RDestimate(stfedu ~ run, data = smol40, cutpoint = 0, bw = 30))




## Item non-response / refusal balance tests ##

# create subdata with all observations
n1 <- ESS6 %>% 
  filter(cntry == "IT")
n1$date <- n1$date - 15981

n2 <- ESS7
n2$date <- n2$date - 16313

n3 <- ESS7
n3$date <- n3$date - 16327

n4 <- ESS7
n4$date <- n4$date - 16474

n5 <- ESS7
n5$date <- n5$date - 16543

n6 <- ESS8
n6$date <- n6$date - 17065

n7 <- ESS8
n7$date <- n7$date - 17107

n8 <- ESS8
n8$date <- n8$date - 17119

n9 <- ESS8
n9$date <- n9$date - 17180

n10 <- ESS8
n10$date <- n10$date - 17217

n11 <- ESS8
n11$date <- n11$date - 17248

n12 <- ESS8
n12$date <- n12$date - 17272

n13 <- ESS8
n13$date <- n13$date - 17334

n14 <- ESS9
n14$date <- n14$date - 17914

n15 <- ESS9
n15$date <- n15$date - 18234

## load OLD ESS 10 data with missing values (new data set does not contain missings) ##
load("ESS10old.RData")
## recode old data ##
ESS10old <- tidyr::separate(ESS10old, inwds, c("date", "time"), sep = " ")
ESS10old$date <- as.Date(ESS10old$date)
ESS10old$date <- as.numeric(ESS10old$date)

n16 <- ESS10old
n16$date <- n16$date - 18978



# Item Non-Response Balance Tests

# creating non-response dummies
n1 <- n1 %>% 
  filter(date > -31 & date < 31)
n1 <- n1 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n1 <- n1 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n1 <- n1 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n1 <- n1 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n1 <- n1 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n1 <- n1 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na1 <- rdd_data(n1$date, n1$date, cutpoint = 0, covar = n1$NRmig)
covarTest_mean(na1)
nb1 <- rdd_data(n1$date, n1$date, cutpoint = 0, covar = n1$NReco)
covarTest_mean(nb1)
nc1 <- rdd_data(n1$date, n1$date, cutpoint = 0, covar = n1$NRcul)
covarTest_mean(nc1)
nd1 <- rdd_data(n1$date, n1$date, cutpoint = 0, covar = n1$NRsame)
covarTest_mean(nd1)
ne1 <- rdd_data(n1$date, n1$date, cutpoint = 0, covar = n1$NRdiff)
covarTest_mean(ne1)
nf1 <- rdd_data(n1$date, n1$date, cutpoint = 0, covar = n1$NRpoor)
covarTest_mean(nf1)

# creating non-response dummies
n2 <- n2 %>% 
  filter(date > -31 & date < 31)
n2 <- n2 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n2 <- n2 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n2 <- n2 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n2 <- n2 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n2 <- n2 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n2 <- n2 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na2 <- rdd_data(n2$date, n2$date, cutpoint = 0, covar = n2$NRmig)
covarTest_mean(na2)
nb2 <- rdd_data(n2$date, n2$date, cutpoint = 0, covar = n2$NReco)
covarTest_mean(nb2)
nc2 <- rdd_data(n2$date, n2$date, cutpoint = 0, covar = n2$NRcul)
covarTest_mean(nc2)
nd2 <- rdd_data(n2$date, n2$date, cutpoint = 0, covar = n2$NRsame)
covarTest_mean(nd2)
ne2 <- rdd_data(n2$date, n2$date, cutpoint = 0, covar = n2$NRdiff)
covarTest_mean(ne2)
nf2 <- rdd_data(n2$date, n2$date, cutpoint = 0, covar = n2$NRpoor)
covarTest_mean(nf2)

# creating non-response dummies
n3 <- n3 %>% 
  filter(date > -31 & date < 31)
n3 <- n3 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n3 <- n3 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n3 <- n3 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n3 <- n3 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n3 <- n3 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n3 <- n3 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na3 <- rdd_data(n3$date, n3$date, cutpoint = 0, covar = n3$NRmig)
covarTest_mean(na3)
nb3 <- rdd_data(n3$date, n3$date, cutpoint = 0, covar = n3$NReco)
covarTest_mean(nb3)
nc3 <- rdd_data(n3$date, n3$date, cutpoint = 0, covar = n3$NRcul)
covarTest_mean(nc3)
nd3 <- rdd_data(n3$date, n3$date, cutpoint = 0, covar = n3$NRsame)
covarTest_mean(nd3)
ne3 <- rdd_data(n3$date, n3$date, cutpoint = 0, covar = n3$NRdiff)
covarTest_mean(ne3)
nf3 <- rdd_data(n3$date, n3$date, cutpoint = 0, covar = n3$NRpoor)
covarTest_mean(nf3)

# creating non-response dummies
n4 <- n4 %>% 
  filter(date > -31 & date < 31)
n4 <- n4 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n4 <- n4 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n4 <- n4 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n4 <- n4 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n4 <- n4 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n4 <- n4 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na4 <- rdd_data(n4$date, n4$date, cutpoint = 0, covar = n4$NRmig)
covarTest_mean(na4)
nb4 <- rdd_data(n4$date, n4$date, cutpoint = 0, covar = n4$NReco)
covarTest_mean(nb4)
nc4 <- rdd_data(n4$date, n4$date, cutpoint = 0, covar = n4$NRcul)
covarTest_mean(nc4)
nd4 <- rdd_data(n4$date, n4$date, cutpoint = 0, covar = n4$NRsame)
covarTest_mean(nd4)
ne4 <- rdd_data(n4$date, n4$date, cutpoint = 0, covar = n4$NRdiff)
covarTest_mean(ne4)
nf4 <- rdd_data(n4$date, n4$date, cutpoint = 0, covar = n4$NRpoor)
covarTest_mean(nf4)

# creating non-response dummies
n5 <- n5 %>% 
  filter(date > -31 & date < 31)
n5 <- n5 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n5 <- n5 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n5 <- n5 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n5 <- n5 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n5 <- n5 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n5 <- n5 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na5 <- rdd_data(n5$date, n5$date, cutpoint = 0, covar = n5$NRmig)
covarTest_mean(na5)
nb5 <- rdd_data(n5$date, n5$date, cutpoint = 0, covar = n5$NReco)
covarTest_mean(nb5)
nc5 <- rdd_data(n5$date, n5$date, cutpoint = 0, covar = n5$NRcul)
covarTest_mean(nc5)
nd5 <- rdd_data(n5$date, n5$date, cutpoint = 0, covar = n5$NRsame)
covarTest_mean(nd5)
ne5 <- rdd_data(n5$date, n5$date, cutpoint = 0, covar = n5$NRdiff)
covarTest_mean(ne5)
nf5 <- rdd_data(n5$date, n5$date, cutpoint = 0, covar = n5$NRpoor)
covarTest_mean(nf5)

# creating non-response dummies
n6 <- n6 %>% 
  filter(date > -31 & date < 31)
n6 <- n6 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n6 <- n6 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n6 <- n6 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n6 <- n6 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n6 <- n6 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n6 <- n6 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na6 <- rdd_data(n6$date, n6$date, cutpoint = 0, covar = n6$NRmig)
covarTest_mean(na6)
nb6 <- rdd_data(n6$date, n6$date, cutpoint = 0, covar = n6$NReco)
covarTest_mean(nb6)
nc6 <- rdd_data(n6$date, n6$date, cutpoint = 0, covar = n6$NRcul)
covarTest_mean(nc6)
nd6 <- rdd_data(n6$date, n6$date, cutpoint = 0, covar = n6$NRsame)
covarTest_mean(nd6)
ne6 <- rdd_data(n6$date, n6$date, cutpoint = 0, covar = n6$NRdiff)
covarTest_mean(ne6)
nf6 <- rdd_data(n6$date, n6$date, cutpoint = 0, covar = n6$NRpoor)
covarTest_mean(nf6)

# creating non-response dummies
n7 <- n7 %>% 
  filter(date > -31 & date < 31)
n7 <- n7 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n7 <- n7 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n7 <- n7 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n7 <- n7 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n7 <- n7 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n7 <- n7 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na7 <- rdd_data(n7$date, n7$date, cutpoint = 0, covar = n7$NRmig)
covarTest_mean(na7)
nb7 <- rdd_data(n7$date, n7$date, cutpoint = 0, covar = n7$NReco)
covarTest_mean(nb7)
nc7 <- rdd_data(n7$date, n7$date, cutpoint = 0, covar = n7$NRcul)
covarTest_mean(nc7)
nd7 <- rdd_data(n7$date, n7$date, cutpoint = 0, covar = n7$NRsame)
covarTest_mean(nd7)
ne7 <- rdd_data(n7$date, n7$date, cutpoint = 0, covar = n7$NRdiff)
covarTest_mean(ne7)
nf7 <- rdd_data(n7$date, n7$date, cutpoint = 0, covar = n7$NRpoor)
covarTest_mean(nf7)

# creating non-response dummies
n8 <- n8 %>% 
  filter(date > -31 & date < 31)
n8 <- n8 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n8 <- n8 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n8 <- n8 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n8 <- n8 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n8 <- n8 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n8 <- n8 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na8 <- rdd_data(n8$date, n8$date, cutpoint = 0, covar = n8$NRmig)
covarTest_mean(na8)
nb8 <- rdd_data(n8$date, n8$date, cutpoint = 0, covar = n8$NReco)
covarTest_mean(nb8)
nc8 <- rdd_data(n8$date, n8$date, cutpoint = 0, covar = n8$NRcul)
covarTest_mean(nc8)
nd8 <- rdd_data(n8$date, n8$date, cutpoint = 0, covar = n8$NRsame)
covarTest_mean(nd8)
ne8 <- rdd_data(n8$date, n8$date, cutpoint = 0, covar = n8$NRdiff)
covarTest_mean(ne8)
nf8 <- rdd_data(n8$date, n8$date, cutpoint = 0, covar = n8$NRpoor)
covarTest_mean(nf8)

# creating non-response dummies
n9 <- n9 %>% 
  filter(date > -31 & date < 31)
n9 <- n9 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n9 <- n9 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n9 <- n9 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n9 <- n9 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n9 <- n9 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n9 <- n9 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na9 <- rdd_data(n9$date, n9$date, cutpoint = 0, covar = n9$NRmig)
covarTest_mean(na9)
nb9 <- rdd_data(n9$date, n9$date, cutpoint = 0, covar = n9$NReco)
covarTest_mean(nb9)
nc9 <- rdd_data(n9$date, n9$date, cutpoint = 0, covar = n9$NRcul)
covarTest_mean(nc9)
nd9 <- rdd_data(n9$date, n9$date, cutpoint = 0, covar = n9$NRsame)
covarTest_mean(nd9)
ne9 <- rdd_data(n9$date, n9$date, cutpoint = 0, covar = n9$NRdiff)
covarTest_mean(ne9)
nf9 <- rdd_data(n9$date, n9$date, cutpoint = 0, covar = n9$NRpoor)
covarTest_mean(nf9)

# creating non-response dummies
n10 <- n10 %>% 
  filter(date > -31 & date < 31)
n10 <- n10 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n10 <- n10 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n10 <- n10 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n10 <- n10 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n10 <- n10 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n10 <- n10 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na10 <- rdd_data(n10$date, n10$date, cutpoint = 0, covar = n10$NRmig)
covarTest_mean(na10)
nb10 <- rdd_data(n10$date, n10$date, cutpoint = 0, covar = n10$NReco)
covarTest_mean(nb10)
nc10 <- rdd_data(n10$date, n10$date, cutpoint = 0, covar = n10$NRcul)
covarTest_mean(nc10)
nd10 <- rdd_data(n10$date, n10$date, cutpoint = 0, covar = n10$NRsame)
covarTest_mean(nd10)
ne10 <- rdd_data(n10$date, n10$date, cutpoint = 0, covar = n10$NRdiff)
covarTest_mean(ne10)
nf10 <- rdd_data(n10$date, n10$date, cutpoint = 0, covar = n10$NRpoor)
covarTest_mean(nf10)

# creating non-response dummies
n11 <- n11 %>% 
  filter(date > -31 & date < 31)
n11 <- n11 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n11 <- n11 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n11 <- n11 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n11 <- n11 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n11 <- n11 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n11 <- n11 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na11 <- rdd_data(n11$date, n11$date, cutpoint = 0, covar = n11$NRmig)
covarTest_mean(na11)
nb11 <- rdd_data(n11$date, n11$date, cutpoint = 0, covar = n11$NReco)
covarTest_mean(nb11)
nc11 <- rdd_data(n11$date, n11$date, cutpoint = 0, covar = n11$NRcul)
covarTest_mean(nc11)
nd11 <- rdd_data(n11$date, n11$date, cutpoint = 0, covar = n11$NRsame)
covarTest_mean(nd11)
ne11 <- rdd_data(n11$date, n11$date, cutpoint = 0, covar = n11$NRdiff)
covarTest_mean(ne11)
nf11 <- rdd_data(n11$date, n11$date, cutpoint = 0, covar = n11$NRpoor)
covarTest_mean(nf11)

# creating non-response dummies
n12 <- n12 %>% 
  filter(date > -31 & date < 31)
n12 <- n12 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n12 <- n12 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n12 <- n12 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n12 <- n12 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n12 <- n12 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n12 <- n12 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na12 <- rdd_data(n12$date, n12$date, cutpoint = 0, covar = n12$NRmig)
covarTest_mean(na12)
nb12 <- rdd_data(n12$date, n12$date, cutpoint = 0, covar = n12$NReco)
covarTest_mean(nb12)
nc12 <- rdd_data(n12$date, n12$date, cutpoint = 0, covar = n12$NRcul)
covarTest_mean(nc12)
nd12 <- rdd_data(n12$date, n12$date, cutpoint = 0, covar = n12$NRsame)
covarTest_mean(nd12)
ne12 <- rdd_data(n12$date, n12$date, cutpoint = 0, covar = n12$NRdiff)
covarTest_mean(ne12)
nf12 <- rdd_data(n12$date, n12$date, cutpoint = 0, covar = n12$NRpoor)
covarTest_mean(nf12)

# creating non-response dummies
n13 <- n13 %>% 
  filter(date > -31 & date < 31)
n13 <- n13 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n13 <- n13 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n13 <- n13 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n13 <- n13 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n13 <- n13 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n13 <- n13 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na13 <- rdd_data(n13$date, n13$date, cutpoint = 0, covar = n13$NRmig)
covarTest_mean(na13)
nb13 <- rdd_data(n13$date, n13$date, cutpoint = 0, covar = n13$NReco)
covarTest_mean(nb13)
nc13 <- rdd_data(n13$date, n13$date, cutpoint = 0, covar = n13$NRcul)
covarTest_mean(nc13)
nd13 <- rdd_data(n13$date, n13$date, cutpoint = 0, covar = n13$NRsame)
covarTest_mean(nd13)
ne13 <- rdd_data(n13$date, n13$date, cutpoint = 0, covar = n13$NRdiff)
covarTest_mean(ne13)
nf13 <- rdd_data(n13$date, n13$date, cutpoint = 0, covar = n13$NRpoor)
covarTest_mean(nf13)

# creating non-response dummies
n14 <- n14 %>% 
  filter(date > -31 & date < 31)
n14 <- n14 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n14 <- n14 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n14 <- n14 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n14 <- n14 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n14 <- n14 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n14 <- n14 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na14 <- rdd_data(n14$date, n14$date, cutpoint = 0, covar = n14$NRmig)
covarTest_mean(na14)
nb14 <- rdd_data(n14$date, n14$date, cutpoint = 0, covar = n14$NReco)
covarTest_mean(nb14)
nc14 <- rdd_data(n14$date, n14$date, cutpoint = 0, covar = n14$NRcul)
covarTest_mean(nc14)
nd14 <- rdd_data(n14$date, n14$date, cutpoint = 0, covar = n14$NRsame)
covarTest_mean(nd14)
ne14 <- rdd_data(n14$date, n14$date, cutpoint = 0, covar = n14$NRdiff)
covarTest_mean(ne14)
nf14 <- rdd_data(n14$date, n14$date, cutpoint = 0, covar = n14$NRpoor)
covarTest_mean(nf14)

# creating non-response dummies
n15 <- n15 %>% 
  filter(date > -31 & date < 31)
n15 <- n15 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n15 <- n15 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n15 <- n15 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n15 <- n15 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n15 <- n15 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n15 <- n15 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na15 <- rdd_data(n15$date, n15$date, cutpoint = 0, covar = n15$NRmig)
covarTest_mean(na15)
nb15 <- rdd_data(n15$date, n15$date, cutpoint = 0, covar = n15$NReco)
covarTest_mean(nb15)
nc15 <- rdd_data(n15$date, n15$date, cutpoint = 0, covar = n15$NRcul)
covarTest_mean(nc15)
nd15 <- rdd_data(n15$date, n15$date, cutpoint = 0, covar = n15$NRsame)
covarTest_mean(nd15)
ne15 <- rdd_data(n15$date, n15$date, cutpoint = 0, covar = n15$NRdiff)
covarTest_mean(ne15)
nf15 <- rdd_data(n15$date, n15$date, cutpoint = 0, covar = n15$NRpoor)
covarTest_mean(nf15)

# creating non-response dummies
n16 <- n16 %>% 
  filter(date > -31 & date < 31)
n16 <- n16 %>%
  mutate(NRmig = ifelse(imwbcnt == 77 | imwbcnt == 88 | imwbcnt == 99,1,0))
n16 <- n16 %>% 
  mutate(NReco = ifelse(imbgeco == 77 | imbgeco == 88 | imbgeco == 99,1,0))
n16 <- n16 %>% 
  mutate(NRcul = ifelse(imueclt == 77 | imueclt == 88 | imueclt == 99,1,0))
n16 <- n16 %>% 
  mutate(NRsame = ifelse(imsmetn == 7 | imsmetn == 8 | imsmetn == 9,1,0))
n16 <- n16 %>% 
  mutate(NRdiff = ifelse(imdfetn == 7 | imdfetn == 8 | imdfetn == 9,1,0))
n16 <- n16 %>% 
  mutate(NRpoor = ifelse(impcntr == 7 | impcntr == 8 | impcntr == 9,1,0))
# difference in means tests with non-response dummies between treatment and control group
na16 <- rdd_data(n16$date, n16$date, cutpoint = 0, covar = n16$NRmig)
covarTest_mean(na16)
nb16 <- rdd_data(n16$date, n16$date, cutpoint = 0, covar = n16$NReco)
covarTest_mean(nb16)
nc16 <- rdd_data(n16$date, n16$date, cutpoint = 0, covar = n16$NRcul)
covarTest_mean(nc16)
nd16 <- rdd_data(n16$date, n16$date, cutpoint = 0, covar = n16$NRsame)
covarTest_mean(nd16)
ne16 <- rdd_data(n16$date, n16$date, cutpoint = 0, covar = n16$NRdiff)
covarTest_mean(ne16)
nf16 <- rdd_data(n16$date, n16$date, cutpoint = 0, covar = n16$NRpoor)
covarTest_mean(nf16)



